package com.task.core.domain.info;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson2.JSON;
import com.task.common.info.IpFraudInfo;

import lombok.Data;

/**
 * @author 迪迦.
 * @date 2025/1/16 11:25
 */
@Data
public class ClientIpFraudInfo {
  private Integer id;
  private String code;
  private String ipFraudName;
  private String ipFraudPlatformName;
  private Map<String, Object> config;

  public static List<ClientIpFraudInfo> getList(List<IpFraudInfo> ipFrauds) {
    if (CollectionUtils.isEmpty(ipFrauds)) {
      return null;
    }
    List<ClientIpFraudInfo> list = new ArrayList<>();
    ipFrauds.forEach(f -> {
      list.add(new ClientIpFraudInfo(f));
    });

    return list;
  }

  public ClientIpFraudInfo(IpFraudInfo ipFraud) {
    this.id = ipFraud.getId();
    this.code = ipFraud.getCode();
    this.ipFraudName = ipFraud.getIpFraudName();
    this.ipFraudPlatformName = ipFraud.getIpFraudPlatformName();
    if (!StringUtils.isEmpty(ipFraud.getConfig())) {
      this.config = JSON.parseObject(ipFraud.getConfig());
    }
  }

  //private String description;
}
